<?php
    $idnam = $_GET['idnam'];
    $idkhoi = $_GET['idkhoi'];
    $idlop = $_GET['idlop'];
    $id_mon = $_GET['id_mon'];
    $templ = new XTemplate('sites/tpml/qldiem/listall.html');
    $sql = "SELECT hocsinh.id AS id_hocsinh, hocsinh.name AS tenhocsinh,hocsinh.mahs AS mahs , khoi.ten AS tenkhoi, lop.ten AS tenlop, namhoc.ten AS tennamhoc, mark . * , monhoc.ten AS tenmonhoc
            FROM hocsinh
            LEFT JOIN lop ON hocsinh.lop = lop.id
            LEFT JOIN khoi ON khoi.id = lop.id_khoi
            LEFT JOIN namhoc ON khoi.id_namhoc = namhoc.id
            LEFT JOIN mark ON mark.hocsinh_id = hocsinh.id
            LEFT JOIN monhoc ON monhoc.id = mark.monhoc_id
            WHERE lop.id = $idnam
            AND khoi.id = $idkhoi
            AND namhoc.id = $idlop
            AND mark.monhoc_id=$id_mon
        ";
    $data = $db->GetArray($sql);
  // print_r($data);
    $templ->assign('idnam',$idnam);
        $templ->assign('idkhoi',$idkhoi);
        $templ->assign('idlop',$idlop);
        $templ->assign('idmon',$id_mon);

    if(count($data)!=0){
        $tplabc = new XTemplate('sites/views/hocsinh/list.html');
        foreach($data as $value){
            $value['diemmieng'] = json_decode($value['diemmieng']);
            $value['diemmieng'] = implode('  ',$value['diemmieng']);
            
            $value['diem15ph'] = json_decode($value['diem15ph']);
            $value['diem15ph'] = implode('  ',$value['diem15ph']);
            
            $value['diem1t'] = json_decode($value['diem1t']);
            $value['diem1t'] = implode('  ',$value['diem1t']);
            
            $value['diemhk'] = json_decode($value['diemhk']);
            $value['diemhk'] = implode('  ',$value['diemhk']);
			$templ->insert_loop('LISTALLDIEM.LOOP', array('LOOP'=>$value));
		}
       
        $templ->assign('tit','Danh sách điểm');
        $templ->assign('idmon',$id);
        $templ->parse('LISTALLDIEM');
        $maincontent = $templ->text('LISTALLDIEM');
      
    }else{
       $maincontent = '<p>Không có dữ liệu</p>';
    }
?>